/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.websec.conta;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;



@FacesConverter(value="contaConverter")
public class ContaConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if (value != null && !value.equals("")) {
            ContaRN  c = new ContaRN();
            return c.buscarPorId(Integer.parseInt(value));
        }
        return null;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if (value instanceof Conta) {
        	Conta c = (Conta) value;
            return String.valueOf(c.getIdConta());
        }
        return "";
    }

}
